home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / raytrace / pov / gen / diamndrv / diamond2.bas < prev    next >
Encoding:
BASIC Source File  |  1993-04-23  |  5.0 KB  |  137 lines

  1. ' Diamond generator by Ken Koehler
  2. ' Originally written for DKB
  3. ' Modified by Jeroen van den Bos for use with the Persistance of Vision -
  4. ' raytracer : April 1993
  5.  
  6. defdbl a-z
  7. const FALSE= 0
  8. const TRUE = NOT FALSE
  9. CONST PI = 3.141592653589#
  10. full.scene=TRUE
  11.  
  12. print
  13. print "DIAMOND generator for the Persistance of Vision ray-tracer"
  14. print "Original by Ken Koehler. Modified by Jeroen v.d.Bos for use with PoV 1.0"
  15. print
  16. input "Number of sides          :";s
  17. input "Top Radius    from center:";tr
  18. input "Top Height    from center:";th
  19. input "Center Radius from center:";cr
  20. input "Bottom Depth  from center:";bd
  21. screen 1 : color 7
  22. if tr>cr then wy=tr else wy=cr        ' get max dimension
  23. if th>wy then bound=th else bound=wy
  24. if bd>wy then bound=bd
  25. wy=wy*1.1                ' allow % extra screen space
  26. wx=wy*1.5                ' adjust aspect ratio
  27. window (-wx,-wy) - (wx,wy)
  28.   open "diamond.pov" for output as #1
  29.   if full.scene then gosub WritePreText
  30.   print #1,
  31.   print #1,"#declare Diamond = composite {
  32.   print #1,"       // s =";s ;"  tr=";tr;"  th=";th;"  cr=";cr;"  bd=";bd
  33.   ''' Constant
  34.   if tr>cr then size=tr else size=cr
  35.   if th+bd>size then size=th+bd
  36.   ark=2*pi/s/2
  37.   b1x=0         : b1y=-bd: b1z=0
  38.   a4x=0         : a4y= th: a4z=0
  39.   ''' Prep
  40.   long.side=TRUE
  41.   pointx=cos(-2.5*ark)    : pointz=sin(-2.5*ark)
  42.   a1x=pointx   *cr  : a1y=00 : a1z=pointz   *cr
  43.   c3x=pointx   *tr  : c3y=th : c3z=pointz   *tr
  44. ' line (  0,  0)-(c3x,c3z),1
  45.   line (c3x,c3z)-(a1x,a1z),3
  46.   for angle = (-1.5*ark) to (2*pi)+(-2.5*ark) step ark*2
  47.       if long.side=TRUE  then pointx=cos(angle)     : pointz=sin(angle)
  48.       if long.side=FALSE then pointx=cos(angle+ark) : pointz=sin(angle+ark)
  49.       c1x=pointx*cr : c1y= 00: c1z=pointz*cr
  50.       b2x=pointx*tr : b2y= th: b2z=pointz*tr
  51. '     line (  0,  0)-(b2x,b2z),1
  52.       line (b2x,b2z)-(c1x,c1z),3
  53.       line (c1x,c1z)-(a1x,a1z),3
  54.       line (b2x,b2z)-(c3x,c3z),1
  55.       gosub WritePoint
  56.       a1x=c1x : a1y=c1y : a1z=c1z
  57.       c3x=b2x : c3y=b2y : c3z=b2z
  58.       long.side=NOT long.side
  59.   next angle
  60.   print #1,"   // bounded_by {";
  61.   if th>bd then print #1,"   // ** WARNING: Watch for bounding off of top surface **"
  62.   print #1,using "   sphere { <0 0 0> ###.## }";bound*1.01;' MAX+1%
  63.   print #1," }"
  64.   print #1,"  }
  65.   if full.scene then gosub WritePostText
  66.   close #1
  67. while inkey$="":wend
  68. end
  69.  
  70. WritePreText:
  71.   print #1,"#include ";chr$(34);"shapes.inc";chr$(34)
  72.   print #1,"#include ";chr$(34);"colors.inc";chr$(34)
  73.   print #1,
  74.   print #1,"#declare DiamondTex = texture {
  75.   print #1,"    reflection 0.4
  76.   print #1,"    color Red
  77.   print #1,"    specular 1.0
  78.   print #1,"    roughness 0.001
  79.   print #1,"}
  80. return
  81.  
  82. WritePostText:
  83.   print #1,"
  84.   print #1,"camera {
  85.   print #1,using "   location <0.0  6.0  ####.##>";-size*1.5
  86.   print #1,"   direction <0.0 0.0  1.0>
  87.   print #1,"   up  <0.0  1.0  0.0>
  88.   print #1,"   right <1.33333 0.0 0.0>
  89.   print #1,     "   look_at ";
  90.   print #1,using        "<0.0 ####.## 0.0>";th-(size/2)
  91.   print #1,"}
  92.   print #1,"
  93.   print #1,"// Put down the beloved famous raytrace green/yellow checkered floor
  94.   print #1,"object {
  95.   print #1,using "   plane { <0.0 1.0 0.0> ####.## }";-bd*1.10 ' 10% lower
  96.   print #1,"   texture {
  97.   print #1,"      checker color Yellow color Green
  98.   print #1,using "      scale < ####.## ####.## ####.##>";wy/2;wy/2;wy/2
  99.   print #1,"      ambient 0.3
  100.   print #1,"      diffuse 0.7
  101.   print #1,"   }
  102.   print #1,"}
  103.   print #1,"
  104.   print #1,"// Put up a ceiling
  105.   print #1,"object {
  106.   print #1,"   plane { <0.0 1.0 0.0> 130.00 }"
  107.   print #1,"   texture {
  108.   print #1,"      checker color White color Blue
  109.   print #1,using "      scale < ####.## ####.## ####.##>";wy*5;wy*5;wy*5
  110.   print #1,"      ambient 0.3
  111.   print #1,"      diffuse 0.7
  112.   print #1,"   }
  113.   print #1,"}
  114.   print #1,"
  115.   print #1,"composite { Diamond }
  116.   print #1,"
  117.   print #1,"// Lights please!
  118.   print #1,"object {
  119.   print #1,"   light_source {
  120.   print #1,"      <100.0 120.0 -130.0>
  121.   print #1,"      color White
  122.   print #1,"   }
  123.   print #1,"}"
  124. return
  125.  
  126. WritePoint:
  127.   current.point%=current.point%+1
  128.   print #1, using "       // Side #### ";current.point%
  129.   print #1, using "    object { triangle { <###.#### ###.#### ###.####> <###.#### ###.#### ###.####> <###.#### ###.#### ###.####> }";a1x;a1y;a1z  ;c1x;c1y;c1z  ;b1x;b1y;b1z;
  130.   print #1,      " texture { DiamondTex } }"
  131.   print #1, using "    object { triangle { <###.#### ###.#### ###.####> <###.#### ###.#### ###.####> <###.#### ###.#### ###.####> }" ;a1x;a1y;a1z  ;c1x;c1y;c1z  ;b2x;b2y;b2z;
  132.   print #1,      " texture { DiamondTex } }"
  133.   print #1, using "    object { triangle { <###.#### ###.#### ###.####> <###.#### ###.#### ###.####> <###.#### ###.#### ###.####> }" ;a1x;a1y;a1z  ;b2x;b2y;b2z  ;c3x;c3y;c3z;
  134.   print #1,      " texture { DiamondTex } }"
  135.   print #1, using "    object { triangle { <###.#### ###.#### ###.####> <###.#### ###.#### ###.####> <###.#### ###.#### ###.####> }" ;a4x;a4y;a4z  ;b2x;b2y;b2z  ;c3x;c3y;c3z;
  136.   print #1,      " texture { DiamondTex } }"
  137. return